package de.hsb.ai.domain;

import game.Move;
import jade.content.onto.BCReflectiveIntrospector;
import jade.content.onto.BasicOntology;
import jade.content.onto.Ontology;
import jade.content.onto.SerializableOntology;
import jade.content.schema.AgentActionSchema;
import jade.content.schema.ConceptSchema;
import jade.content.schema.ObjectSchema;
import jade.content.schema.PrimitiveSchema;
import jade.domain.FIPAAgentManagement.ExceptionOntology;
import jade.domain.introspection.IntrospectionOntology;

import org.slf4j.LoggerFactory;

import de.hsb.ai.domain.action.GetMove;
import de.hsb.ai.domain.action.StartGame;

/**
 * Basic ontology for the game.
 */
public class ScotlandJadeOntology extends Ontology implements ScotlandJadeVocabulary {
	
	private static final long serialVersionUID = -8324125743737333532L;
	
	private static final Ontology instance = new ScotlandJadeOntology();
	
	public static Ontology getInstance() {
		return instance;
	}
	
	protected ScotlandJadeOntology() {
		super(NAME, new Ontology[]{IntrospectionOntology.getInstance(), ExceptionOntology.getInstance(), SerializableOntology.getInstance()}, new BCReflectiveIntrospector());
		try {
			add(new ConceptSchema(GAME_START_EVENT), GameStarted.class);
			add(new ConceptSchema(MOVE_EVENT), MoveEvent.class);
			add(new ConceptSchema(GAME_OVER), GameOver.class);
			add(new ConceptSchema(GAME_INFO), GameInfo.class);
			add(new ConceptSchema(MOVE), Move.class);
			
			add(new AgentActionSchema(MOVE_GET), GetMove.class);
			add(new AgentActionSchema(GAME_START), StartGame.class);
			
			ConceptSchema cs = (ConceptSchema) getSchema(GAME_INFO);
			cs.add(GAME_INFO_PLAYERS, (ConceptSchema) getSchema(BasicOntology.AID), MIN_PLAYERS, MAX_PLAYERS);
			
			cs = (ConceptSchema) getSchema(GAME_START_EVENT);
			cs.add(GAME_INFO, (ConceptSchema) getSchema(GAME_INFO), ConceptSchema.MANDATORY);
			
			cs = (ConceptSchema) getSchema(GAME_OVER);
			cs.add(GAME_OVER_WINNER, (ConceptSchema) getSchema(BasicOntology.AID), ConceptSchema.MANDATORY);
			cs.add(GAME_OVER_MESSAGE, (PrimitiveSchema) getSchema(BasicOntology.STRING), ConceptSchema.OPTIONAL);
			
			cs = (ConceptSchema) getSchema(MOVE);
			cs.add(MOVE_NODE, (PrimitiveSchema) getSchema(BasicOntology.INTEGER), ConceptSchema.MANDATORY);
			cs.add(MOVE_TYPE, (PrimitiveSchema) getSchema(BasicOntology.INTEGER), ConceptSchema.MANDATORY);
			
			cs = ((ConceptSchema) getSchema(MOVE_EVENT));
			cs.add(MOVE_EVENT_PLAYER_IDX, (PrimitiveSchema) getSchema(BasicOntology.INTEGER), ConceptSchema.MANDATORY);
			cs.add(MOVE_EVENT_PLAYER, (ConceptSchema) getSchema(BasicOntology.AID), ConceptSchema.MANDATORY);
			cs.add(MOVE_EVENT_FROM, (PrimitiveSchema) getSchema(BasicOntology.INTEGER), ConceptSchema.MANDATORY);
			cs.add(MOVE, (ConceptSchema) getSchema(MOVE), ConceptSchema.MANDATORY);
			cs.add(GAME_ROUND, (PrimitiveSchema) getSchema(BasicOntology.INTEGER), ConceptSchema.MANDATORY);
			
			AgentActionSchema as = (AgentActionSchema) getSchema(MOVE_GET);
			as.add(MOVE_GET_MOVE_OPTIONS, (ConceptSchema) getSchema(MOVE), 1, ObjectSchema.UNLIMITED);
			as.setResult((ConceptSchema) getSchema(MOVE));
			
			as = (AgentActionSchema) getSchema(GAME_START);
			as.add(GAME_INFO, (ConceptSchema) getSchema(GAME_INFO), AgentActionSchema.MANDATORY);
		} catch (Exception e) {
			LoggerFactory.getLogger(getName()).error("initalizing ontology", e);
		} 
	}
}
